package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduVideo;
import com.atguigu.eduservice.service.EduVideoService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author kaixuan
 * @since 2020-05-30
 */
@RestController
@RequestMapping("/eduservice/video")
//@CrossOrigin //跨域访问
public class EduVideoController {

    @Autowired
    private EduVideoService videoService;

    @ApiOperation("根据小节id逻辑删除章节")
    @DeleteMapping("{id}")
    public R deleteVideo(@ApiParam(value = "小节id",name = "id",required = true)@PathVariable String id){
        boolean falg = videoService.removeById(id);
        if (falg){
            return R.ok();
        }else {
            return R.error();
        }
    }

    @ApiOperation("添加小节信息")
    @PostMapping("addVideo")
    public R addVideo(@RequestBody EduVideo video){
        boolean falg = videoService.save(video);
        if (falg){
            return R.ok();
        }else {
            return R.error();
        }
    }

    @ApiOperation("修改小节信息")
    @PostMapping("updateVideo")
    public R updateVideo(@RequestBody EduVideo video){
        boolean falg = videoService.updateById(video);
        if (falg){
            return R.ok();
        }else {
            return R.error();
        }
    }

    @ApiOperation("修改小节信息")
    @GetMapping("getVideo/{id}")
    public R updateVideo(@ApiParam(value = "id",name = "小节",required = true)@PathVariable String id){
        EduVideo video = videoService.getById(id);
        return R.ok().data("video",video);
    }
}

